// pages/apply/apply.js
var http = require("../../utils/http.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    apply: null,
    addr: '',
    name: '',
    phone: '',
    longitude: '',
    latitude: '',
    city:'',
    merchantName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let ths = this
    wx.showLoading();
    var params = {
      url: "/user/getApplyInfo",
      method: "GET",
      data: {},
      callBack: function (res) {
        wx.hideLoading();
        ths.setData({
          apply: res.content,
          addr:res.content.merchantAddress
        });
      }
    };
    http.request(params);
  },
  translate: function () {
    let ths = this
    wx.chooseLocation({
      success: (res) => {
        let address=res.address
        let start=address.indexOf("省");
        let end=address.indexOf("市")
        let city=address.substring(start+1,end);
        ths.setData({
          addr: res.address + " " + res.name,
          longitude: res.longitude,
          latitude: res.latitude,
          city:city
        })
      }
    })
  },
  onSave() {
    wx.showLoading();
    let ths=this
    var params = {
      url: "/user/ApplyMerchant",
      method: "post",
      data: {
        merchantAddress: ths.data.addr,
        city:ths.data.city,
        merchantLinkman: ths.data.name,
        merchantPhone: ths.data.phone,
        merchantLongitude: ths.data.longitude,
        merchantLatitude: ths.data.latitude,
        merchantName:ths.data.merchantName
      },
      callBack: function (res) {
        wx.hideLoading();
        ths.setData({
          apply: res.content,
          addr:res.content.merchantAddress
        });
      }
    };
    http.request(params);
  },
  onReceiverInput: function (e) {
    this.setData({
      name: e.detail.value
    });
  },

  onMobileInput: function (e) {
    this.setData({
      phone: e.detail.value
    });
  },

  onMerchantName: function (e) {
    this.setData({
      merchantName: e.detail.value
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})